package com.ricchieri.manage.bean;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import com.ricchieri.common.BusinessSettings;
import com.ricchieri.filter.UserFilter;
import com.ricchieri.model.User;
import com.ricchieri.util.FacesUtil;

@ManagedBean(name = "viewUserMB")
@ViewScoped
public class ViewUserManageBean extends GenericManageBean {

	private static final long serialVersionUID = -4431457088573798836L;
	
	private User selecterdUser;
	private UserFilter userFilter;
	
	@PostConstruct
	public void init() {
		selecterdUser = (User) FacesUtil.getParametersFlash(BusinessSettings.KEY_USER);
		userFilter = (UserFilter) FacesUtil.getParametersFlash(BusinessSettings.KEY_FILTER);
		
		if(selecterdUser == null) {
			FacesUtil.redirectToNavigationCase(BusinessSettings.SEARCH_USER);
		}
	}

	public User getSelecterdUser() {
		return selecterdUser;
	}

	public void setSelecterdUser(User selecterdUser) {
		this.selecterdUser = selecterdUser;
	}
	
	public String doBackToSearchUser() {
		FacesUtil.addParametersFlash(BusinessSettings.KEY_FILTER, userFilter);
		return BusinessSettings.SEARCH_USER;
	}
}
